﻿Imports QLBH.frmMain
Imports BUS
Imports GVariable.Variable
Public Class uerHTDangNhap
    Dim uerCtrMBanHang As uerMainBanHang
    Dim busNhanVien As New CBusiNhanVien()
    Private Function KiemTraDuLieu() As Boolean
        Dim strTDN As String = txtTenDangNhap.Text.Trim()
        Dim strP As String = txtPass.Text.Trim()
        If (strTDN = "") Then
            MessageBox.Show("Chưa nhập tên đăng nhập.", "Error: 1001", _
                            MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtTenDangNhap.Focus()
            Return False
        End If

        If strP = "" Then
            MessageBox.Show("Chưa nhập mật khẩu.", "Error: 1002", _
                           MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtPass.Focus()
            Return False
        End If

        If (LayMaNhanVien(strTDN, strP) = "") Then
            If (intKiemTraKetNoi = 0) Then
                MessageBox.Show("Không kết nối đuợc CSDL")
                Return False
            End If
            MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu.", "Error: 1003", _
                          MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtTenDangNhap.Focus()
            Return False
        End If
        Return True
    End Function
    Private Sub btnDangNhap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDangNhap.Click
        'busNhanVien.DocQuyen(maNV)

        If (KiemTraDuLieu() = True) Then
            Dim maNV As String = LayMaNhanVien(txtTenDangNhap.Text, txtPass.Text)
            strMaNVHienTai = maNV
            QuyenNhanVien(maNV)
            frmMain.TatUerCtr()
        Else

        End If
    End Sub
    Private Function LayMaNhanVien(ByVal tenDN As String, ByVal pass As String) As String
        Dim maNV As String = ""
        maNV = busNhanVien.LayMaNV(tenDN, pass)
        Return maNV
    End Function

    Private Sub QuyenNhanVien(ByVal maNV As String)
        Dim lQuyen As List(Of Integer)
        lQuyen = busNhanVien.LayQuyen(maNV)
        frmMain.BatTatButton(1, lQuyen(1), lQuyen(2), lQuyen(3), lQuyen(4), lQuyen(5), lQuyen(6))
    End Sub
    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Dim dlResult As DialogResult
        dlResult = MessageBox.Show("Bạn có muốn thoát khỏi chương trình?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
        If dlResult = Windows.Forms.DialogResult.Yes Then
            frmMain.Close()
        End If
    End Sub

    Private Sub btnApDungCSDL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApDungCSDL.Click
        uID = txtUser.Text
        pWD = txtPassW.Text
        Dim strData As String = txtDB.text
        strVConn = "Server=localhost;Database=" & strData & ";Uid=" & uID & ";Pwd=" & pWD & ""
        labHuongDan.Text = "Điền tên đăng nhập và mật khẩu"
        gbDangNhap.Visible = True
        ePlCauHinhCSDL.Expanded = False
        txtTenDangNhap.Focus()
    End Sub

    Private Sub ePlCauHinhCSDL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ePlCauHinhCSDL.Click

    End Sub
End Class
